package com.test.prolenders.analytics_prolenders.data_sdk_prolenders.task_prolenders;

import android.content.Context;
import android.text.TextUtils;

import com.test.prolenders.analytics_prolenders.data_sdk_prolenders.beans_prolenders.ASRequestPms_prolenders;
import com.test.prolenders.analytics_prolenders.data_sdk_prolenders.http_prolenders.ASReqstManger_prolenders;
import com.test.prolenders.analytics_prolenders.data_sdk_prolenders.logger_prolenders.ASLger_prolenders;
import com.test.prolenders.analytics_prolenders.data_sdk_prolenders.services_prolenders.ASNtwkIfo_prolenders;
import com.test.prolenders.config_prolenders.CountryConfig_prolenders;
import com.test.prolenders.config_prolenders.Paths_prolenders;

import java.util.function.Supplier;


public class ASDevcWfiTsk_prolenders implements Supplier<String> {

    private final static String TAG = "ASDeviceWifiTask";

    private final String mTaskId;
    private final Context mContext;

    public ASDevcWfiTsk_prolenders(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get()  {
        // 日志标记
        ASLger_prolenders.d(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(Paths_prolenders.PATH_NETWORK)) {
            return mTaskId + "";
        }

        String infoBeans = ASNtwkIfo_prolenders.getZipString(mContext);
        if (TextUtils.isEmpty(infoBeans)) {
            // 日志标记
            ASLger_prolenders.d(TAG, "获取wifi信息出错：数据为空");
            return mTaskId + "";
        }

        ASRequestPms_prolenders netParams = new ASRequestPms_prolenders();
        netParams.setDWG(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams(Paths_prolenders.PATH_NETWORK);

        // 上报请求
        String url = CountryConfig_prolenders.getInstance().getCommonPath();
        new ASReqstManger_prolenders.Builder().setReqId(this.mTaskId).setUrl(url).setBody(result).build().doPostRqst();

        return mTaskId + "";
    }

}
